from flask import request, g
from .jwt_util import verify_jwt

def jwt_authentication():
    """认证jwt"""
    # 取出token
    header = request.headers.get('Authorization')
    g.user_id = None
    g.is_refresh = False
    if header and header.startswith('Bearer '):
        token = header[7:]
        # 认证token
        payload = verify_jwt(token)
        if payload:
            # 取出数据, 并使用g变量来记录数据
            g.user_id = payload.get('payload')
            g.is_refresh = payload.get('is_refresh')

